<template>
  <basic-container>
    <div class="avue-crud__search">
      <div class="avue-form" style="width: 100%;">
        <form class="el-form">
          <div class="el-row" span="24">
            <div class="avue-group avue-group--header" index="0" active="1">
              <div role="tablist" aria-multiselectable="true" class="el-collapse">
                <div class="el-collapse-item is-active">
                  <div role="tab" aria-expanded="true" aria-controls="el-collapse-content-4400" aria-describedby="el-collapse-content-4400">
                    <div role="button" id="el-collapse-head-4400" tabindex="0" class="el-collapse-item__header is-active"><i class="el-collapse-item__arrow el-icon-arrow-right is-active"></i></div>
                  </div>
                  <div role="tabpanel" aria-labelledby="el-collapse-head-4400" id="el-collapse-content-4400" class="el-collapse-item__wrap">
                    <div class="el-collapse-item__content">
                      <div class="avue-form__group avue-form__group--flex">
                        <div class="el-col el-col-offset-0 el-col-xs-24 avue-form__row el-col-12" style="padding-left: 10px; padding-right: 10px;">
                          <div class="el-form-item el-form-item--feedback el-form-item--mini avue-form__item--">
                            <label for="projectNo" class="el-form-item__label" style="width: 180px;">
                              <el-select size="mini" v-model="productType" placeholder="类型" @change="changeProdType">
                                <el-option v-for="item in prodtypeList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey">
                                </el-option>
                              </el-select>
                            </label>
                            <div class="el-form-item__content" style="margin-left:180px;">
                              <div class="el-tooltip el-input el-input--mini el-input--suffix avue-input" search="true" minwidth="120" sortable="sortable" span="6" gutter="20" labelwidth="180" aria-describedby="el-tooltip-3815" tabindex="0">
                                <el-select size="mini" filterable v-model="productId" placeholder="产品名称（产品编码）" @change="changeProduct">
                                  <el-option v-for="item in productList" :key="item.value" :label="item.label" :value="item.value">
                                  </el-option>
                                </el-select>
                              </div>
                            </div>
                          </div>
                        </div>
                        <!-- <div class="el-col el-col-offset-0 el-col-xs-24 avue-form__row el-col-8" style="padding-left: 10px; padding-right: 10px;">
                          <div class="el-form-item el-form-item--feedback el-form-item--mini avue-form__item--">
                            <label for="projectNo" class="el-form-item__label" style="width: 180px;">
                              <el-select size="mini" v-model="specialType" placeholder="特殊类型" clearable @change="changeSpecialType">
                                <el-option v-for="item in specialtypeList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey">
                                </el-option>
                              </el-select>
                            </label>
                          </div>
                        </div> -->
                        <!-- <div class="el-col el-col-12 avue-form__menu avue-form__menu--right" style="padding: 0px;">
                          <div class="el-form-item el-form-item--feedback el-form-item--mini">
                            <div class="el-form-item__content" style="margin-left: 0px;">
                              <button type="button" class="el-button el-button--primary el-button--mini" @click.stop='searchChange'>
                                <i class="el-icon-search"></i><span>搜 索</span>
                              </button>
                            </div>
                          </div>
                        </div> -->
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
    <avue-crud class='featureTable' :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form" :permission="permissionList" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave" :before-open="beforeOpen" @selection-change="selectionChange" @refresh-change="refreshChange" :span-method="spanMethod" @on-load="onLoad">
      <template slot="menuRight">
        <table-right :crud='$refs.crud' :data='data' :searchBtn='false' :columnBtn='true' :addPermission="permission.publiccraft_feature_add&&this.productId" :handleDelete="handleDelete" :delPermission="permission.publiccraft_feature_delete" :refreshChange='refreshChange'>
          <!-- <el-button type="text" icon="el-icon-download" v-if="permission.publiccraft_feature_export" @click="handleExport">导出</el-button> -->
        </table-right>
      </template>
      <template slot="notation" slot-scope="{row}">
        <img style="width: auto; height: 25px" :src="row.notation" alt="">
      </template>
      <template slot-scope="{row}" slot='standard'>
        <el-image v-if="row.standardType=='2'" style="width: 40px; height: 40px" :src="row.standard" :preview-src-list="[row.standard]">
        </el-image>
        <span v-else>{{row.standard}}</span>
      </template>
      <template slot="scopeForm" slot-scope="scope">
        <avue-crud :option="scopeOption" :data="scopeData" v-model="scopeForm" :before-open="beforeScopeOpen" @row-del="rowScopeDel" @row-update="rowScopeUpdate" @row-save="rowScopeSave">
          <template slot="drawingScFlag" slot-scope="{row}">
            <el-radio-group v-model="row.drawingScFlag" class="radio_group_self">
              <el-radio v-for="item in specialSymnols" :key="item.id" :label="item.id">
                <img style="width: 30px; height: 25px" :src="item.notation">
              </el-radio>
              <el-radio label="1">
                <span style="display: inline-block; width: 30px; height: 25px; position: relative; top: -7px; font-size: 12px;">取消</span>
              </el-radio>
            </el-radio-group>
          </template>
        </avue-crud>
      </template>
      <template slot="drawingScFlagForm">
        <el-radio-group v-model="form.drawingScFlag" class="radio_group_self">
          <el-radio v-for="item in specialSymnols" :key="item.id" :label="item.id">
            <img style="width: 30px; height: 25px" :src="item.notation">
          </el-radio>
          <el-radio label="1">
            <span style="display: inline-block; width: 30px; height: 25px; position: relative; top: -7px; font-size: 12px;">取消</span>
          </el-radio>
        </el-radio-group>
      </template>
      <template slot="infoForm" slot-scope="scope">
        <avue-crud ref="infoCrud" :option="infoOption" v-model="infoForm" :data="infoData" :upload-before="beforeUpload" @row-save="infoRowSave" @row-update="infoRowUpdate" @row-del="inforRowDel" :before-open="beforeInfoOpen">
          <template slot-scope="{row}" slot='standard'>
            <span v-if="row.standardType=='1'">{{row.standard}}</span>
            <el-image v-else style="width: 50px; height: 50px" :src="row.standard" :preview-src-list="[row.standard]">
            </el-image>
          </template>
          <template slot="menuForm">
            <el-button icon="el-icon-circle-plus" v-if="infoOpenType=='add'" :loading="goon" size="mini" plain type="primary" @click.stop="saveAndGoon()">保存并继续</el-button>
          </template>
          <template slot="fixtureNoType" slot-scope="{item,value,label}">
            <span>{{ item.materialName }}({{item.materialNo}})</span>
          </template>
          <template slot-scope="{row}" slot="menu">
            <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
              <el-button icon="el-icon-edit" size="small" type="text" @click.stop="$refs.infoCrud.rowEdit(row,row.$index)" v-if="permission.publiccraft_feature_edit"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
              <el-button icon="el-icon-delete" size="small" type="text" @click.stop="inforRowDel(row,row.$index)" v-if="permission.publiccraft_feature_delete"></el-button>
            </el-tooltip>
          </template>
        </avue-crud>
      </template>
      <template slot-scope="{row}" slot="menu">
        <el-tooltip class="item" effect="dark" content="查看" placement="bottom">
          <el-button icon="el-icon-view" size="small" type="text" @click.stop="$refs.crud.rowView(row,row.$index)" v-if="permission.publiccraft_feature_view"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="编辑" placement="bottom">
          <el-button icon="el-icon-edit" size="small" type="text" @click.stop="$refs.crud.rowEdit(row,row.$index)" v-if="permission.publiccraft_feature_edit"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
          <el-button icon="el-icon-delete" size="small" type="text" @click.stop="rowDel(row)" v-if="permission.publiccraft_feature_delete"></el-button>
        </el-tooltip>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getFeatureList,
  addFeature,
  removeFeature,
  updateFeature,
  getFeature,
  getProdProcess,
  getFeatures,
} from '@/api/project/productData/processData';
import { getQualityList } from '@/api/project/information/base';
import { masterProducts } from '@/api/project/productData/product';
import { getEquipments } from '@/api/project/productData/equipment';
import { getBusinessList } from '@/api/zidian';
import { mapGetters } from 'vuex';
import { init } from '@/mixins/init';
import { getToken } from '@/util/auth';
import {getSpecialSymbols} from '@/api/publicbasic/specialSymbols.js'

export default {
  mixins: [init],
  data() {
    return {
      specialSymnols: [],
      infoOpenType: '',
      goon: false,
      productType: '',
      specialType: '',
      // specialtypeList: [],
      prodtypeList: [],
      productList: [],
      option: {
        dialogHeight: '100%',
        dialogWidth: '80%',
        page: false,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: false,
        menuWidth: 100,
        columnBtn: true,
        filterBtn: true,
        dialogClickModal: false,
        labelWidth: 120,
        column: [
          {
            label: '产品名称',
            prop: 'materialName',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            label: '产品图号',
            prop: 'innerDrawingNo',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            label: '产品编码',
            prop: 'materialNo',
            disabled: true,
            editDisplay: false,
            viewDisplay: false,
            span: 8,
            hide: true,
            showColumn: false,
          },
          {
            labelWidth: 0,
            label: '',
            prop: 'scope',
            span: 24,
            hide: true,
            formslot: true,
            addDisplay: true,
            editDisplay: false,
            viewDisplay: false,
          },
          {
            label: '产品特性',
            prop: 'productSc',
            span: 8,
            addDisplay: false,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
            // rules: [
            //   {
            //     required: true,
            //     message: '请输入产品特性',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '过程特性',
            prop: 'procedureSc',
            addDisplay: false,
            span: 8,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
          },
          {
            label: '特性分类',
            prop: 'scKind',
            addDisplay: false,
            minWidth: 120,
            span: 8,
            type: 'select',
            dicData: [],
            // dicUrl: '/api/blade-system/dict-biz/dictionary?code=featureType',
            props: {
              label: 'quaType',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择特性分类',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '特殊特性标识',
            prop: 'notation',
            slot: true,
            display: false,
            span: 8,
            minWidth: 100,
            maxlength: 30,
          },
          {
            label: '特殊特性标识',
            prop: 'drawingScFlag',
            addDisplay: false,
            formslot: true,
            hide: true,
            showColumn: false,
            span: 8,
            minWidth: 100,
            maxlength: 30,
          },
          // {
          //   label: '安全/重要特性',
          //   prop: 'importantFeature',
          //   dataType: 'string',
          //   type: 'upload',
          //   propsHttp: {
          //     res: 'data',
          //   },
          //   minWidth: 100,
          //   addDisplay: false,
          //   span: 8,
          //   listType: 'picture-card',
          //   tip: '只能上传jpg/png文件，且不超过500kb',
          //   action: '/imgupload',
          // },
          // {
          //   label: '关键特性',
          //   prop: 'keyFeature',
          //   dataType: 'string',
          //   type: 'upload',
          //   propsHttp: {
          //     res: 'data',
          //   },
          //   addDisplay: false,
          //   span: 8,
          //   listType: 'picture-card',
          //   tip: '只能上传jpg/png文件，且不超过500kb',
          //   action: '/imgupload',
          // },
          // {
          //   label: '图纸标识',
          //   prop: 'drawingScFlag',
          //   addDisplay: false,
          //   span: 12,
          //   minWidth: 150,
          //   maxlength: 5,
          //   overHidden: true,
          // },
          {
            label: '检验规范',
            prop: 'standard',
            display: false,
            slot: true,
            span: 12,
            minWidth: 150,
            maxlength: 5,
            overHidden: true,
          },
          {
            label: '测量技术',
            prop: 'checkToolName',
            display: false,
            span: 24,
            minWidth: 150,
            overHidden: true,
          },
          // {
          //   label: '工序名称',
          //   prop: 'procedureId',
          //   type: 'select',
          //   minWidth: 120,
          //   dicData: [],
          //   props: {
          //     label: 'procedureName',
          //     value: 'id',
          //   },
          //   span: 24,
          //   rules: [
          //     {
          //       required: true,
          //       message: '请选择工序名称',
          //       trigger: 'blur',
          //     },
          //   ],
          // },
          {
            labelWidth: 0,
            label: '',
            prop: 'info',
            addDisplay: false,
            span: 24,
            hide: true,
            showColumn: false,
            formslot: true,
          },
        ],
      },
      scopeOption: {
        page: false,
        menuWidth: 130,
        addRowBtn: true,
        cellBtn: true,
        editBtn: false,
        addBtn: false,
        column: [
          {
            label: '产品特性',
            prop: 'productSc',
            span: 12,
            cell: true,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
            // rules: [
            //   {
            //     required: true,
            //     message: '请输入产品特性',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '过程特性',
            prop: 'procedureSc',
            span: 12,
            cell: true,
            minWidth: 150,
            overHidden: true,
            maxlength: 30,
          },
          {
            label: '特性分类',
            prop: 'scKind',
            minWidth: 120,
            span: 12,
            cell: true,
            type: 'select',
            dicData: [],
            // dicUrl: '/api/blade-system/dict-biz/dictionary?code=featureType',
            props: {
              label: 'quaType',
              value: 'id',
            },
            rules: [
              {
                required: true,
                message: '请选择特性分类',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '特殊特性标识',
            prop: 'drawingScFlag',
            display: false,
            slot: true,
            minWidth: 120,
          },
          // {
          //   label: '安全/重要特性',
          //   prop: 'importantFeature',
          //   dataType: 'string',
          //   type: 'upload',
          //   propsHttp: {
          //     res: 'data',
          //   },
          //   minWidth: 100,
          //   cell: true,
          //   span: 8,
          //   listType: 'picture-card',
          //   tip: '只能上传jpg/png文件，且不超过500kb',
          //   action: '/imgupload',
          // },
          // {
          //   label: '关键特性',
          //   prop: 'keyFeature',
          //   dataType: 'string',
          //   type: 'upload',
          //   propsHttp: {
          //     res: 'data',
          //   },
          //   cell: true,
          //   span: 8,
          //   listType: 'picture-card',
          //   tip: '只能上传jpg/png文件，且不超过500kb',
          //   action: '/imgupload',
          // },
          // {
          //   label: '图纸标识',
          //   prop: 'drawingScFlag',
          //   span: 12,
          //   minWidth: 150,
          //   maxlength: 5,
          //   cell: true,
          //   overHidden: true,
          // },
        ],
      },
      scopeData: [],
      scopeForm: {},
      infoOption: {
        dialogHeight: '100%',
        dialogWidth: '600',
        page: false,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        // selection: true,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        addBtn: true,
        menuWidth: 100,
        columnBtn: true,
        filterBtn: true,
        dialogClickModal: false,
        labelWidth: 120,
        column: [
          {
            label: '检验规范标识',
            prop: 'standardType',
            type: 'select',
            value: '2',
            dicData: [
              {
                label: '输入',
                value: '1',
              },
              {
                label: '上传',
                value: '2',
              },
            ],
            rules: [
              {
                required: true,
                message: '请选择检验规范标识',
                trigger: 'change',
              },
            ],
            span: 24,
            minWidth: 150,
            maxlength: 5,
            overHidden: true,
          },
          {
            label: '检验规范',
            prop: 'standard',
            slot: true,
            dataType: 'string',
            type: 'upload',
            propsHttp: {
              res: 'data',
              url: 'link',
            },
            span: 24,
            limit: 1,
            listType: 'picture-img',
            tip: '只能上传一张jpg、jpeg或png文件，且不超过10M',
            action: '/api/attach/uploadFile',
            // accept: 'png,jpg,jpeg',
            minWidth: 150,
            overHidden: true,
            rules: [
              {
                required: true,
                message: '请上传检验规范',
                trigger: 'change',
              },
            ],
          },
          {
            label: '样本容量',
            prop: 'capacity',
            span: 24,
            minWidth: 150,
            maxlength: 20,
            overHidden: true,
            rules: [
              {
                required: true,
                message: '请输入样本容量',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '样本频率',
            prop: 'frequency',
            span: 24,
            minWidth: 150,
            maxlength: 100,
            overHidden: true,
            rules: [
              {
                required: true,
                message: '请输入样本频率',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '测量技术',
            prop: 'technology',
            span: 24,
            minWidth: 150,
            maxlength: 20,
            overHidden: true,
            // rules: [
            //   {
            //     required: true,
            //     message: '请输入测量技术',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '测量设备',
            prop: 'fixtureNo',
            type: 'select',
            filterable: true,
            typeslot: true,
            typeformat(item, label, value) {
              return `${item.materialName}(${item.materialNo})`;
            },
            dicData: [],
            props: {
              label: 'materialName',
              value: 'materialNo',
            },
            span: 24,
            minWidth: 150,
            overHidden: true,
            // rules: [
            //   {
            //     required: true,
            //     message: '请选择测量设备',
            //     trigger: 'blur',
            //   },
            // ],
          },
          {
            label: '检测方法',
            prop: 'testMethod',
            type: 'select',
            minWidth: 100,
            span: 24,
            filterable: true,
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=testMethod',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择检测方法',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '公差计算方法',
            prop: 'calculationMethod',
            type: 'select',
            minWidth: 100,
            span: 24,
            filterable: true,
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=calculationMethod',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请输入样本频率',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '最大值',
            prop: 'maximumValue',
            span: 24,
            // type: 'number',
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: '请输入最大值',
                trigger: 'blur',
              },
              {
                pattern: /^(\-|\+?)\d+(\.\d+)?$/,
                message: '请输入正确的数字格式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '最小值',
            prop: 'minimumValue',
            span: 24,
            // type: 'number',
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: '请输入最小值',
                trigger: 'blur',
              },
              {
                pattern: /^(\-|\+?)\d+(\.\d+)?$/,
                message: '请输入正确的数字格式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '标准值',
            prop: 'standardValue',
            span: 24,
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                required: true,
                message: '请输入标准值',
                trigger: 'blur',
              },
              {
                pattern: /^(\-|\+?)\d+(\.\d+)?$/,
                message: '请输入正确的数字格式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '正公差',
            prop: 'positiveTolerance',
            span: 24,
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                pattern: /^(\-|\+?)\d+(\.\d+)?$/,
                message: '请输入正确的数字格式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '负公差',
            prop: 'negativeTolerance',
            span: 24,
            addDisplay: false,
            editDisplay: false,
            rules: [
              {
                pattern: /^(\-|\+?)\d+(\.\d+)?$/,
                message: '请输入正确的数字格式',
                trigger: 'blur',
              },
            ],
          },
          {
            label: '特征符号',
            prop: 'characteristic',
            type: 'select',
            minWidth: 100,
            span: 24,
            filterable: true,
            dicUrl: '/api/blade-system/dict-biz/dictionary?code=specialSymbols',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
          },
        ],
      },
      infoForm: {
        standardType: '',
        standard: '',
        capacity: '',
        frequency: '',
        technology: '',
        fixtureNo: '',
        testMethod: '',
        calculationMethod: '',
      },
      infoData: [],
      data: [],
      productId: '',
      searchProductId: '',
      materialName: '', //产品名称
      innerDrawingNo: '', //产品图号
      materialNo: '', //产品编码
    };
  },
  watch: {
    'infoForm.calculationMethod'(val) {
      this.hideColumn();
      if (val == 1) {
        this.findObject(this.infoOption.column, 'maximumValue').addDisplay = true;
        this.findObject(this.infoOption.column, 'maximumValue').editDisplay = true;
        this.findObject(this.infoOption.column, 'minimumValue').addDisplay = true;
        this.findObject(this.infoOption.column, 'minimumValue').editDisplay = true;
      } else if (val == 2) {
        this.findObject(this.infoOption.column, 'standardValue').addDisplay = true;
        this.findObject(this.infoOption.column, 'standardValue').editDisplay = true;
        this.findObject(this.infoOption.column, 'positiveTolerance').addDisplay = true;
        this.findObject(this.infoOption.column, 'positiveTolerance').editDisplay = true;
        this.findObject(this.infoOption.column, 'negativeTolerance').addDisplay = true;
        this.findObject(this.infoOption.column, 'negativeTolerance').editDisplay = true;
      } else if (val == 3) {
        this.findObject(this.infoOption.column, 'maximumValue').addDisplay = true;
        this.findObject(this.infoOption.column, 'maximumValue').editDisplay = true;
      } else if (val == 4) {
        this.findObject(this.infoOption.column, 'minimumValue').addDisplay = true;
        this.findObject(this.infoOption.column, 'minimumValue').editDisplay = true;
      }
    },
    'infoForm.standardType'(val, oldVal) {
      if (val == '1') {
        this.findObject(this.infoOption.column, 'standard').type = 'input';
        this.findObject(this.infoOption.column, 'standard').tip = '';
        this.findObject(this.infoOption.column, 'standard').rules = [
          {
            required: true,
            message: '请输入检验规范',
            trigger: 'blur',
          },
        ];
      } else if (val == '2') {
        this.findObject(this.infoOption.column, 'standard').type = 'upload';
        this.findObject(this.infoOption.column, 'standard').tip = '只能上传一张jpg、jpeg或png文件，且不超过10M';
        this.findObject(this.infoOption.column, 'standard').rules = [
          {
            required: true,
            message: '请上传检验规范',
            trigger: 'change',
          },
        ];
      }
      if (oldVal) {
        this.$set(this.infoForm, 'standard', '');
      }
    },
    'infoForm.testMethod'(val) {
      if (val == 1) {
        this.findObject(this.infoOption.column, 'calculationMethod').rules[0].required = false;
      } else {
        this.findObject(this.infoOption.column, 'calculationMethod').rules[0].required = true;
      }
    },
  },
  computed: {
    ...mapGetters(['userInfo', 'permission']),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.publiccraft_feature_add, false),
        viewBtn: this.vaildData(this.permission.publiccraft_feature_view, false),
        delBtn: this.vaildData(this.permission.publiccraft_feature_delete, false),
        editBtn: this.vaildData(this.permission.publiccraft_feature_edit, false),
      };
    },
  },
  created() {
    this.init();
    getSpecialSymbols().then(res => {
      this.specialSymnols = res.data.data
    })
  },
  mounted() {},
  methods: {
    handleExport() {
      this.$confirm('是否导出特性清单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        window.open(
          `/api/blade-user/export-user?${this.website.tokenHeader}=${getToken()}&account=${this.search.account}&realName=${
            this.search.realName
          }`
        );
      });
    },
    hideColumn() {
      this.findObject(this.infoOption.column, 'maximumValue').addDisplay = false;
      this.findObject(this.infoOption.column, 'maximumValue').editDisplay = false;
      this.findObject(this.infoOption.column, 'minimumValue').addDisplay = false;
      this.findObject(this.infoOption.column, 'minimumValue').editDisplay = false;
      this.findObject(this.infoOption.column, 'standardValue').addDisplay = false;
      this.findObject(this.infoOption.column, 'standardValue').editDisplay = false;
      this.findObject(this.infoOption.column, 'positiveTolerance').addDisplay = false;
      this.findObject(this.infoOption.column, 'positiveTolerance').editDisplay = false;
      this.findObject(this.infoOption.column, 'negativeTolerance').addDisplay = false;
      this.findObject(this.infoOption.column, 'negativeTolerance').editDisplay = false;
    },
    changeProdType(value) {
      this.productId = '';
      switch (value) {
        case '1':
          this.getProducts();
          break;
        case '2':
          this.getMoulds();
          break;
      }
    },
    changeProduct(value) {
      if (!value) {
        return;
      }
      this.searchChange();
    },
    changeSpecialType(value) {
      this.searchChange();
    },
    searchChange() {
      this.searchProductId = this.productId;
      this.productList.every((item) => {
        if (item.value == this.productId) {
          this.materialName = item.materialName;
          this.innerDrawingNo = item.innerDrawingNo;
          this.materialNo = item.materialNo;
          return false;
        } else {
          return true;
        }
      });
      this.onLoad();
    },
    beforeUpload(file, done, loading, column) {
      const isLt10M = file.size / 1024 / 1024 < 100;
      if (!isLt10M) {
        this.$message.error('上传文件大小不能超过 100MB!');
        loading();
        return false;
      }
      var reg = /^.*\.(?:pdf|jpg|jpeg|png)$/i;
      if (!reg.test(file.name)) {
        this.$message.error('请上传PDF、jpg、jpeg或png格式文件!');
        loading();
        return false;
      }
      done(file);
    },
    vaildData(row) {
      if (!row.technology && !row.fixtureNo) {
        return false;
      } else {
        return true;
      }
    },
    infoRowSave(row, done, loading) {
      let valid = this.vaildData(row);
      if (!valid) {
        this.$message.error('测量技术和测量设备至少填一个');
        loading();
        this.goon = false;
        return false;
      }
      if (row.calculationMethod == 2 && !row.positiveTolerance && !row.negativeTolerance) {
        this.$message.error('正公差和负公差至少填一个');
        loading();
        this.goon = false;
        return false;
      }
      if (row.maximumValue && row.minimumValue && row.minimumValue * 1 > row.maximumValue * 1) {
        this.$message.error('最小值应该小于最大值');
        loading();
        this.goon = false;
        return false;
      }
      this.infoData.push(row);
      if (this.goon) {
        loading();
        for (let key in this.$refs.infoCrud.value) {
          this.$refs.infoCrud.value[key] = null;
        }
        this.$refs.infoCrud.value.standardType = '2';
        this.hideColumn();
        this.goon = false;
        // this.$refs.infoCrud.clearValidate()
      } else {
        done();
      }
    },
    infoRowUpdate(row, index, done, loading) {
      if (row.calculationMethod == 1) {
        row.standardValue = '';
        row.positiveTolerance = '';
        row.negativeTolerance = '';
      } else if (row.calculationMethod == 2) {
        row.maximumValue = '';
        row.minimumValue = '';
      } else if (row.calculationMethod == 3) {
        row.minimumValue = '';
        row.standardValue = '';
        row.positiveTolerance = '';
        row.negativeTolerance = '';
      } else if (row.calculationMethod == 4) {
        row.maximumValue = '';
        row.standardValue = '';
        row.positiveTolerance = '';
        row.negativeTolerance = '';
      }
      let valid = this.vaildData(row);
      if (!valid) {
        this.$message.error('测量技术和测量设备至少填一个');
        loading();
        this.goon = false;
        return false;
      }
      if (row.calculationMethod == 2 && !row.positiveTolerance && !row.negativeTolerance) {
        this.$message.error('正公差和负公差至少填一个');
        loading();
        this.goon = false;
        return false;
      }
      if (row.maximumValue && row.minimumValue && row.minimumValue * 1 > row.maximumValue * 1) {
        this.$message.error('最小值应该小于最大值');
        loading();
        this.goon = false;
        return false;
      }
      this.infoData.splice(index, 1, row);
      done();
    },
    inforRowDel(row, index) {
      this.$confirm('确定将此数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.infoData.splice(index, 1);
      });
    },
    beforeInfoOpen(done, type) {
      this.infoOpenType = type;
      if (!this.form.procedureId) {
        this.$message.warning('请先选择工序');
        return false;
      } else {
        if (type == 'add') {
          this.$set(this.infoForm, 'standardType', '2');
          this.$set(this.infoForm, 'standard', '');
          this.$set(this.infoForm, 'capacity', '');
          this.$set(this.infoForm, 'frequency', '');
          this.$set(this.infoForm, 'technology', '');
          this.$set(this.infoForm, 'fixtureNo', '');
          this.$set(this.infoForm, 'calculationMethod', '');
          this.$set(this.infoForm, 'testMethod', '');
          this.$set(this.infoForm, 'characteristic', '');
          this.$set(this.infoForm, 'standardValue', '');
          this.$set(this.infoForm, 'maximumValue', '');
          this.$set(this.infoForm, 'minimumValue', '');
          this.$set(this.infoForm, 'positiveTolerance', '');
          this.$set(this.infoForm, 'negativeTolerance', '');
          this.hideColumn();
        }
        done();
      }
    },
    saveAndGoon() {
      this.$refs.infoCrud.validate((res) => {
        if (res) {
          this.goon = true;
          this.$refs.infoCrud.rowSave();
        } else {
          return false;
        }
      });
    },
    rowScopeSave(row, done, loading) {
      if (!row.productSc&&!row.procedureSc) {
        this.$message.warning('产品特性或过程特性必填一项')
        loading()
        return
      }
      this.scopeData.push(row);
      done();
    },
    rowScopeUpdate(row, index, done, loading) {
      if (!row.productSc&&!row.procedureSc) {
        this.$message.warning('产品特性或过程特性必填一项')
        loading()
        return
      }
      this.scopeData.splice(index, 1, row);
      done();
    },
    rowScopeDel(row, index) {
      this.scopeData.splice(index, 1);
    },
    validScopeData(data) {
      let equipMsg = '';
      if (data.length > 0) {
        data.every((item, index) => {
          if (item.productSc == ''&&item.procedureSc == '') {
            equipMsg = `【产品特性清单】第${index + 1}行 请维护产品特性或过程特性`;
            this.$message.error(equipMsg);
            return false;
          } else if (item.scKind == '') {
            equipMsg = `【产品特性清单】第${index + 1}行 请选择特性分类`;
            this.$message.error(equipMsg);
            return false;
          } else {
            return true;
          }
        });
        if (equipMsg) {
          return false;
        }
      }
      return true;
    },
    rowSave(row, done, loading) {
      if (this.scopeData.length == 0) {
        this.$message.warning('请添加产品特性信息');
        loading();
        return;
      }
      let valid = this.validScopeData(this.scopeData);
      if (!valid) {
        loading();
        return;
      }
      let content = this.scopeData.map((item) => {
        item.productId = this.productId;
        return item;
      });
      addFeature(content).then(
        () => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowUpdate(row, index, done, loading) {
      row.itemVOS = this.infoData;
      if (!row.productSc&&!row.procedureSc) {
        this.$message.warning('产品特性或过程特性必填一项')
        loading()
        return
      }
      updateFeature(row).then(
        () => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          done();
        },
        (error) => {
          window.console.log(error);
          loading();
        }
      );
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return removeFeature(row.id);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return removeFeature(this.ids);
        })
        .then(() => {
          this.onLoad();
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      this.infoData.length = 0;
      this.infoData = [];
      if (type == 'view') {
        this.infoOption.header = false;
        this.infoOption.menu = false;
      } else {
        this.infoOption.header = true;
        this.infoOption.menu = true;
      }
      if (['edit', 'view'].includes(type)) {
        getFeature(this.form.id).then((res) => {
          this.form = res.data.data;
          this.infoData = res.data.data.itemVOS;
        });
      } else {
        for (let k in this.form) {
          this.form[k] = '';
        }
        this.scopeData.length = 0;
        this.scopeData = [];
        this.$set(this.form, 'materialName', this.materialName);
        this.$set(this.form, 'innerDrawingNo', this.innerDrawingNo);
        this.$set(this.form, 'materialNo', this.materialNo);
      }
      done();
    },
    async getProducts() {
      await masterProducts({ productType: 'PC' }).then((res) => {
        if (res.data.data.length == 0) {
          this.$message.error('请先维护产品信息');
          return;
        }
        this.productList = res.data.data.map((item) => {
          return {
            id: item.id,
            label: item.materialName + '(' + item.materialNo + ')',
            value: item.id,
            materialName: item.materialName,
            innerDrawingNo: item.innerDrawingNo,
            materialNo: item.materialNo,
          };
        });
        if (!this.productId) {
          this.productId = res.data.data[0].id;
          this.searchChange();
        }
      });
    },
    getMoulds() {
      getEquipments({ materialFlag: 'EM', quotaFlag: '2' }).then((res) => {
        if (res.data.data.length == 0) {
          this.$message.error('请先维护模具信息');
          return;
        }
        this.productList = res.data.data.map((item) => {
          return {
            id: item.id,
            label: item.materialName + '(' + item.materialNo + ')',
            value: item.id,
            materialName: item.materialName,
            innerDrawingNo: item.innerDrawingNo,
            materialNo: item.materialNo,
          };
        });
        if (!this.productId) {
          this.productId = res.data.data[0].id;
          this.materialName = res.data.data[0].materialName;
          this.searchChange();
        }
      });
    },
    init() {
      getQualityList().then((res) => {
        this.findObject(this.option.column, 'scKind').dicData = res.data.data;
        this.findObject(this.scopeOption.column, 'scKind').dicData = res.data.data;
      });
      // getBusinessList('specialtype').then((res) => {
      //   this.specialtypeList = res.data.data;
      // });
      getBusinessList('feature_source').then((res) => {
        this.prodtypeList = res.data.data;
        this.productType = this.prodtypeList[0].dictKey;
        masterProducts({ productType: 'PC' }).then((res) => {
          if (res.data.data.length == 0) {
            this.$message.error('请先维护产品信息');
            return;
          }
          this.productList = res.data.data.map((item) => {
            return {
              id: item.id,
              label: item.materialName + '(' + item.materialNo + ')',
              value: item.id,
              materialName: item.materialName,
              innerDrawingNo: item.innerDrawingNo,
              materialNo: item.materialNo,
            };
          });
          if (!this.productId) {
            this.productId = res.data.data[0].id;
            this.materialName = res.data.data[0].materialName;
          }
          this.searchChange();
        });
      });
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (
        columnIndex === 0 ||
        columnIndex === 2 ||
        // columnIndex === 3 ||
        columnIndex === 4 ||
        columnIndex === 5 ||
        // columnIndex === 6 ||
        columnIndex === 8
      ) {
        if (row.itemSpan) {
          return {
            rowspan: row.itemSpan,
            colspan: 1,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    addSpanNumber() {
      const KEY_NAME = 'productSc';
      const KEY_ROWSPAN = 'itemSpan';
      var k = 0;
      while (k < this.data.length) {
        this.data[k][KEY_ROWSPAN] = 1;
        for (var i = k + 1; i <= this.data.length - 1; i++) {
          if (this.data[k][KEY_NAME] === this.data[i][KEY_NAME] && this.data[k][KEY_NAME] !== '') {
            this.data[k][KEY_ROWSPAN]++;
          } else {
            break;
          }
        }
        k = i;
      }
    },
    onLoad(page, params = {}) {
      this.loading = true;
      if (!this.searchProductId) {
        return false;
      }
      this.query.productId = this.searchProductId;
      this.query.specialType = this.specialType ? this.specialType : null;
      getFeatureList(Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.data = data;
        this.addSpanNumber();
        this.loading = false;
        this.selectionClear();
      });
      getEquipments({ materialType: 'EJ' }).then((res) => {
        this.findObject(this.infoOption.column, 'fixtureNo').dicData = res.data.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.radio_group_self {
  // height: 25px;
}
.radio_group_self /deep/ .el-radio__input {
  margin-top: -14px;
}
.radio_group_self /deep/ .el-radio {
  margin-right: 10px;
}
</style>
